<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息修改</title>
    <link rel="stylesheet" href="css/user_update.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
</head>

<body>
     <!-- 导航栏 -->
    <div class="nav">
      <img src="img/logo2.jpg" alt="">
      <a class="title" href="myblog_list.html">我的博客系统</a>
      <!-- 用来占据中间位置 -->
      <span class="spacer"></span>
      <a href="blog_list.html">主页</a>
      <a href="blog_add.html">写博客</a>
      <a href="javascript:logout()">注销</a>
      <!-- <a href="#">注销</a> -->
  </div>
  <!-- 版心 -->
  <div class="container">
        <div class="card">
          <h3>用户信息修改</h3>
            <img src="" class="avtar" alt="" id="photo">
            <button onclick="redirectToPhoto()" id="uplodeFile">上传头像</button>
            <div class="row">
              <span>用户名</span>
              <input type="text" id="username">
          </div>
          <div class="row">
            <span>gitee地址 </span>
            <input type="text" id="gitee">
          </div>
          <div class="row">
            <span>性别 </span>
            <input type="text" id="gender">
          </div>
          <div class="row">
            <span>个人简介 </span>
            <input type="text" id="showself">
          </div>
          <div class="row">
            <span>所在地区 </span>
            <input type="text" id="place">
          </div>
          <div class="row">
            <button id="submit" onclick="mysub()">提交</button>
        </div>
    </div>

    <script>
      function redirectToPhoto() {
            window.location.href = "photo.html";
        }
        // 获取左侧个人信息
        function showInfo(){
            jQuery.ajax({
                url:"/user/showinfo",
                type:"POST",
                data:{},
                success:function(result){
                    if(result!=null && result.code==200){
                        $("#photo").attr("src","http://"+ location.host + result.data.photo);
                    }else{
                        alert("个人信息加载失败，请重新刷新再试！");
                    }
                }
            });
        }
        showInfo();
      function mysub() {
            // 1.非空校验
            var username = jQuery("#username");
            var gitee = jQuery("#gitee");
            var gender = jQuery("#gender");
            var showself = jQuery("#showself");
            var place = jQuery("#place");
            if (username.val() == null && gitee.val() == null && gender.val() == null && shiwself.val() == null && place.val() ==null) {
                alert("请重新输入!");
            }
            // 2.ajax 请求登录接口
            jQuery.ajax({
                url: "/user/upinfo",
                type: "POST",
                data: { "username": username.val(), "gitee": gitee.val(),
                        "gender":gender.val(), "showself":showself.val(),
                      "place":place.val()},
                success: function (result) {
                    // 响应的结果
                    if (result != null && result.code == 200 && result.data != null) {
                        location.href = "/myblog_list.html";
                    } else if (result != null && result.code != 200 && result.data == null) {
                        alert(result.msg);
                    }
                }
            });
        }
    </script>
 
</body>

</html>